package com.da.javatest.leetCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author chenlida
 * @date 2019/2/21 16:58
 * @description
 */
public class Code66 {
    public int[] plusOne(int[] digits) {
        List<Integer> list = new ArrayList<>();
        boolean flag = false;
        for (int i = digits.length - 1; i >= 0; i--) {
            int sum = digits[i];
            if (flag) {
                sum++;
                flag = false;
            }
            if (i == digits.length - 1) {
                sum += 1;
            }
            if (sum > 9) {
                sum -= 10;
                flag = true;
            }
            list.add(sum);
        }
        if (flag) {
            list.add(1);
        }
        int[] r = new int[list.size()];
        int index = 0;
        for (int i = list.size() - 1; i >= 0; i--) {
            r[index++] = list.get(i);
        }
        return r;
    }
}
